package com.hnhcyy.goods.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hnhcyy.goods.mapper.GoodsExtendMapper;
import com.hnhcyy.goods.mapper.GoodsMapper;
import com.hnhcyy.goods.pojo.Goods;
import com.hnhcyy.goods.pojo.GoodsAdminQueryParam;
import com.hnhcyy.goods.pojo.GoodsExtend;
import com.hnhcyy.goods.service.RiseInPriceAdminService;

/**
 * 即将涨价service实现类
 * @author gesh
 *
 */
@Service
public class RiseInPriceAdminServiceImpl implements RiseInPriceAdminService {
	
	@Autowired
	GoodsExtendMapper goodsExtendMapper;
	@Autowired
	GoodsMapper goodsMapper;
	
	public static final ObjectMapper MAPPER = new ObjectMapper();
	
	/**
	 * 查询即将涨价商品列表
	 */
	@Override
	public String listRiseInPrice(GoodsAdminQueryParam queryParam) {
		
		System.out.println("-=-=-=-" + queryParam.toString());

		List<Goods> list = goodsMapper.listAllRiseInPriceGoods(queryParam);
		System.out.println("-------->zzz" + list.toString());
		//转化为json字符串返回，因为admin端调用用的是原生feign，直接返回List和Mapper会提示解码错误
		String result = "";
		try {
			result = MAPPER.writeValueAsString(list);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		System.out.println("---->" + result);
		return result;
	}
	
	/**
	 * 更新即将涨价
	 */
	@Override
	public String updateRiseInPrice(GoodsExtend param) {
		
		int deleteResult = goodsExtendMapper.updateRiseInPrice(param);
		
		return deleteResult + "";
	}

}
